package com.sixth.service.Impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sixth.dao.KeycapDao;

import com.sixth.entity.Keycap;
import com.sixth.service.KeycapService;
import com.sixth.util.CommonResult;
import com.sixth.util.TableLayUi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: project01
 * @description:
 * @author: 老魏
 * @create: 2021-12-27 10:55
 **/
@Service("/keycapService")
public class KeycapServiceImpl implements KeycapService {
    @Autowired
    private KeycapDao keycapDao;

    public CommonResult findAlllKeycap(){
        List<Keycap> list= keycapDao.selectAllKeycap();
            return  new CommonResult(0,"",list);
    }

    public TableLayUi findKeycapCondition (int page, int limit, String keycapid,String keycapname){
        PageHelper.startPage(page,limit);
        List<Keycap> keycaps= keycapDao.selectKeycapCondition(keycapid,keycapname);
        PageInfo<Keycap> pageInfo= new PageInfo<Keycap>(keycaps);
        return new  TableLayUi(0,"",pageInfo.getTotal(),pageInfo.getList());
    }

    public  CommonResult delete(Integer keycapid){
        int row = keycapDao.deleteByPrimaryKey(keycapid);
        if (row>0){
            return new CommonResult(2000,"删除成功",null);
        }else {
            return new CommonResult(5000,"删除失败",null);
        }
    }

    public  CommonResult update(Keycap keycap){
        int row = keycapDao.updateByPrimaryKey(keycap);
        if (row>0){
            return new CommonResult(2000,"修改成功",null);
        }else {
            return new CommonResult(5000,"修改失败",null);
        }
    }

    public  CommonResult insert(Keycap keycap){
        int row = keycapDao.insert(keycap);
        if (row>0){
            return new CommonResult(2000,"新增成功",null);
        }else {
            return new CommonResult(5000,"新增失败",null);
        }
    }
}
